from sklearn.ensemble import RandomForestClassifier
from sklearn import datasets
import pickle

# 方法一:python自带的pickle
(X, y) = datasets.load_iris(return_X_y=True)
rfc = RandomForestClassifier(n_estimators=100, max_depth=100)
rfc.fit(X, y)
print(rfc.predict(X[0:1, :]))
# save model 保存模型
f = open('D:/python/data/model3.h5', 'wb')
pickle.dump(rfc, f)
f.close()
# load model 加载模型
f = open('D:/python/data/model3.h5', 'rb')
rfc1 = pickle.load(f)
f.close()
print(rfc1.predict(X[0:1, :]))
